﻿Imports System.Xml
Imports Mysoft.Map.Data
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text

Partial Public Class PubSelect
    Inherits Mysoft.Map.Application.Security.AppPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Diagnostics.Debugger.Break()
        Dim type As String = Request.QueryString("type")
        '显示标题
        If type.ToLower = "company" Then
            Me.mytitle.Text = "请选择末级公司"
        ElseIf type.ToLower = "project" Then
            Me.mytitle.Text = "请选择末级项目"
        ElseIf type.ToLower = "product" Then
            Me.mytitle.Text = "请选择一级产品类型"
        Else
            Me.mytitle.Text = "请选择"
        End If
        '显示清空
        Dim clear As String = Request.QueryString("clear")
        If clear = "1" Then
            Me.btnClear.Visible = True
        End If
        '是否控制全选
        Dim all As String = Request.QueryString("all")
        If all = "1" Then
            Me.chkAll.Checked = True
        End If
        '绑定数据
        BindData(type)
    End Sub


    Protected Sub BindData(ByVal type As String)
        Dim oid As String = Request.QueryString("key")
        Dim strSql As String = ""
        If type.ToLower = "company" Then
            strSql = "SELECT BUName as 'Name',HierarchyCode as 'Code',BUGUID as 'LevelGUID',BUName as 'text',BUGUID as 'guid' " & _
                     "FROM (" & _
                     "      select row.* from myBusinessUnit row inner join myBusinessUnit b on b.buguid='" & oid & "' " & _
                     "      and charindex(b.HierarchyCode,row.HierarchyCode) > 0 and row.IsEndCompany = 1) row  " & _
                     "ORDER BY HierarchyCode ASC "
        ElseIf type.ToLower = "project" Then
            strSql = "SELECT ProjName as 'Name',ProjCode as 'Code',ProjGUID as 'LevelGUID',ProjName as 'text',ProjGUID as 'guid' " & _
                     "FROM p_Project row " & _
                     "WHERE  buguid='" & oid & "' and IfEnd=1 " & _
                     "ORDER BY ProjCode ASC "
        ElseIf type.ToLower = "product" Then
            strSql = "SELECT BProductTypeName as 'Name',BProductTypeCode as 'Code',BuildProductTypeGUID as 'LevelGUID',BProductTypeName as 'text',BuildProductTypeGUID as 'guid' " & _
                     "FROM p_BuildProductType row " & _
                     "WHERE Level = 2 " & _
                     "ORDER BY BProductTypeCode ASC "
        End If
        Me.Repeater1.DataSource = MyDB.GetDataTable(strSql)
        Me.Repeater1.DataBind()
    End Sub

End Class